<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="lib/layui/css/layui.css">
    <script src="lib/layui/layui.js"></script>
    <script src="lib/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="lib/js/functionfield.js"></script>
</head>
<body>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view">查看</a>
</script>
<script type="text/html" id="toolbarDemo">
    <!--<div class="layui-btn-container">-->
        <!--<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckData">批量刪除</button>-->
    <!--</div>-->
</script>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>盘点历史单</legend>
</fieldset>
<form action="" class="layui-form layui-form-pane">
    <div class="layui-inline">
        <label class="layui-form-label">日期范围</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="dateStr" placeholder=" - ">
        </div>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label">盘点单号</label>
        <div class="layui-input-inline">
            <input type="text" id="orderId" autocomplete="off" class="layui-input" placeholder="请输入盘点单号">
        </div>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label">盈亏</label>
        <div class="layui-input-inline">
            <select id="result">
                <option value="">全部</option>
                <option value="0">盘亏单</option>
                <option value="1">盘盈单</option>
            </select>
        </div>
    </div>
    <button type="button" class="layui-btn layui-btn-normal" data-type="reload">查询</button>
    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
</form>

<table class="layui-hide" id="test" lay-filter="test"></table>
</body>
<script>
    layui.use(['laydate','table','form'], function () {
        var laydate = layui.laydate,
            form = layui.form,
            table = layui.table;

        //日期时间范围
        laydate.render({
            elem: '#dateStr'
            , range: true
        });
        table.render({
            elem: '#test',
            url: 'xp/check/getCounterList',
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            id : 'countOrderList',
            title: '用户数据表',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": "", //解析提示文本
                    "count": res.code, //解析数据长度
                    "data": res.obj //解析数据列表
                };
            },
            cols: [
                [
                    {type: 'checkbox'},
                {
                    field: 'countOrderId',
                    title: '盘点单号',
                    align: 'center'
                }, {
                    field: 'createDate',
                    title: '盘点时间',
                    align: 'center'
                }, {
                    field: 'name',
                    title: '盘点类型',
                    align: 'center'
                },{
                    field: 'result',
                    title: '盘点结果',
                    align: 'center',
                    templet: function (d) {
                        if(Number(d.result)>= 0){
                            return "+"+Number(d.result).toFixed(2)
                        }else{
                            return Number(d.result).toFixed(2)
                        }
                    }
                },{
                    fixed: "right",
                    title: '操作',
                    align: 'center',
                    toolbar: '#barDemo'
                }
                ]
            ],
            page: true
        });

        var active = {
            reload: function () {
                var d = $("#dateStr").val();
                var dd = d.split(" - ");
                var beginTime = dd[0];
                var endTime = dd[1];
                if(typeof endTime=="undefined" || typeof beginTime=="undefined" || typeof status=="undefined"){
                    endTime = '';
                    beginTime = '';
                }

                var countOrderId = $("#orderId");
                var type = $("#result").val();
                table.reload( 'countOrderList',{
                    page: {
                        curr: 1
                    },
                    where: {
                        countOrderId: countOrderId.val(),
                        beginTime: beginTime,
                        endTime: endTime,
                        type: type
                    }
                    , method: 'post'
                });
                laydate.render({
                    elem: '#dateStr'
                    , range: true
                });

            }
        };

        $('.layui-form .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'view'){
                layer.open({
                    type: 2,
                    title: data.countOrderId
                    , area: ['600px', '380px']
                    , shade: 0.5
                    , id: 'LAY_layuipro'
                    , btn: ['确认', '取消']
                    , content: 'check_historyOrderInfo.html?countOrderId='+data.countOrderId
                    , success: function (layero,index) {
                        //var iframe = window['layui-layer-iframe'+index];
                        //iframe.tes(data.replenishmentId);
                    }
                });
            }
        });
    })

</script>
</html>